﻿using WikiPlex.Contrib.Renderers;
using Xunit;

namespace WikiPlex.Contrib.Facts.Renderers
{
    public class ColoredTextRendererFacts
    {
        public class CanExpand
        {
            [Fact]
            public void ShouldReturnTrueForValidScopeNames()
            {
                var renderer = new ColoredTextRenderer();

                bool result = renderer.CanExpand(ContribScopeNames.ColoredText);

                Assert.True(result);
            }
        }

        public class Expand
        {
            [Fact]
            public void ShouldReturnUnresolvedTextWithMoreThanOnePipe()
            {
                var renderer = new ColoredTextRenderer();

                string result = renderer.Expand(ContribScopeNames.ColoredText, "ff0000|test|result", x => x, x => x);

                Assert.Equal("<span class=\"unresolved\">Cannot resolve colored text macro, invalid number of parameters.</span>", result);
            }

            [Fact]
            public void ShouldReturnRenderedContent()
            {
                var renderer = new ColoredTextRenderer();

                string result = renderer.Expand(ContribScopeNames.ColoredText, "ff0000|test", x => x, x => x);

                Assert.Equal("<span style=\"color:#ff0000;\">test</span>", result);
            }

            [Fact]
            public void ShouldHtmlEncodeTheText()
            {
                var renderer = new ColoredTextRenderer();

                string result = renderer.Expand(ContribScopeNames.ColoredText, "ff0000|test", x => "encoded", x => x);

                Assert.Equal("<span style=\"color:#ff0000;\">encoded</span>", result);
            }
        }
    }
}
